package com.xyd.servlet;

import com.xyd.entity.User;
import com.xyd.service.UserService;
import com.xyd.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 赵瑞硕
 * 用户管理修改用户信息
 */
@WebServlet("/queryUpdataServlet")
public class UserQueryUpdataServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String euUserId=request.getParameter("userName");
        String euUsername=request.getParameter("name");
        String euPassword=request.getParameter("password");
        String euSex=request.getParameter("sex");
        String euBirthday=request.getParameter("birthday");
        String euMobile=request.getParameter("mobile");
        String euAddress=request.getParameter("address");

        UserService userService=new UserServiceImpl();
        User user=new User(euUserId,euUsername,euPassword,euSex,euBirthday,euMobile,euAddress);
        int result=userService.backupdateUser(user);
        if (result!=0){
            request.getRequestDispatcher("userVisitServlet").forward(request,response);
        }
        else {
            response.sendRedirect("userVisitServlet?updatas=asd");
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
